package com.example.cardgame

import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    // 声明输入控件
    private lateinit var etStudentId: EditText
    private lateinit var etName: EditText
    private lateinit var etGender: EditText
    private lateinit var etPhone: EditText
    private lateinit var etEmail: EditText
    private lateinit var etHighestScore: EditText
    private lateinit var ivAvatar: ImageView  // 头像ImageView

    // 请求码常量
    private val REQUEST_IMAGE_CAPTURE = 1
    private val CAMERA_PERMISSION_REQUEST = 100

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)

        // 处理系统栏边距
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 初始化控件
        etStudentId = findViewById(R.id.student_id)
        etName = findViewById(R.id.name)
        etGender = findViewById(R.id.gender)
        etPhone = findViewById(R.id.phone)
        etEmail = findViewById(R.id.email)
        etHighestScore = findViewById(R.id.highest_score)


        // 修改个人信息按钮（清空输入）
        findViewById<Button>(R.id.modify).setOnClickListener {
            etStudentId.text.clear()
            etName.text.clear()
            etGender.text.clear()
            etPhone.text.clear()
            etEmail.text.clear()
            etHighestScore.text.clear()
            Toast.makeText(this, "可重新输入信息", Toast.LENGTH_SHORT).show()
        }

        // 确认信息按钮（跳转并传递数据）
        findViewById<Button>(R.id.confirm).setOnClickListener {
            // 获取输入内容
            val studentId = etStudentId.text.toString().trim()
            val name = etName.text.toString().trim()
            val gender = etGender.text.toString().trim()
            val phone = etPhone.text.toString().trim()
            val email = etEmail.text.toString().trim()
            val highestScore = etHighestScore.text.toString().trim()

            // 简单校验（至少填写姓名）
            if (name.isEmpty()) {
                Toast.makeText(this, "请输入姓名", Toast.LENGTH_SHORT).show()
                return@setOnClickListener
            }

            // 传递数据到SecondActivity
            val intent = Intent(this, SecondActivity::class.java).apply {
                putExtra("studentId", studentId)
                putExtra("name", name)
                putExtra("gender", gender)
                putExtra("phone", phone)
                putExtra("email", email)
                putExtra("highestScore", highestScore)
            }
            startActivity(intent)
        }
    }
}

